package com.distribution.business.web.controller;

import com.distribution.business.dto.UserInfoDto;
import com.distribution.business.service.UserService;
import com.distribution.business.web.vo.UserVO;
import com.distribution.common.util.annotation.RepeatSubmit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@RestController
@RequestMapping(value = "user")
public class UserController {

    @Autowired
    private UserService userService;

    @RepeatSubmit
    @GetMapping(value = "getusername")
    public String getUserName() {
        log.debug("this is debug");
        log.info("getUserName log打印日志了");
        log.warn("this is warm");
        log.error("this is error");
        return userService.getUserName();
    }

    @GetMapping(value = "getuserinfo")
    public String getUserInfo() {
        return "aaa";
    }

    @GetMapping(value = "getuserinfo2")
    public UserVO getUserInfo2() {
        UserInfoDto userInfoDto = userService.getUserInfo2();
        UserVO user = new UserVO();
        BeanUtils.copyProperties(userInfoDto, user);

        return user;
    }

    @PostMapping(value = "adduser")
    public ResponseEntity addUser(HttpServletRequest request, HttpServletResponse response, @RequestBody UserVO user) {
        ResponseEntity responseEntity = new ResponseEntity(HttpStatus.OK);

        return responseEntity;
    }

}
